package com.zhanghe.study.springcloud2.client.fallback;


import com.zhanghe.study.springcloud2.client.DeptClient;
import com.zhanghe.study.springcloud2.model.Dept;
import com.zhanghe.study.springcloud2.response.CommonResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author zh
 * @date 2021/8/24 10:36
 */
@Component
public class DeptClientFallBackFactory implements FallbackFactory<DeptClient> {

    @Override
    public DeptClient create(Throwable throwable) {
        return new DeptClient() {
            @Override
            public CommonResult<Dept> get(long id) {
                System.out.println("fallback 原因:"+throwable.getMessage());
                CommonResult<Dept> result = new CommonResult<>();
                result.isOk();
                return result;
            }

            @Override
            public String timeout() {
                return null;
            }
        };
    }
}
